package com.bhf.core;

import io.jsonwebtoken.io.Decoders;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.time.temporal.ChronoUnit;

/**
 * @author pwq
 */
@Data
@ConfigurationProperties(prefix = "jwt.token")
@Component
public class JwtAuthConfigs implements Serializable {

    private static final long serialVersionUID = 4363927270820508307L;
    /**
     * secret key.
     */
    private String secretKey;

    /**
     * secret key byte array.
     */
    private byte[] secretKeyBytes;

    /**
     * Token validity time(seconds).
     */
    @DurationUnit(ChronoUnit.SECONDS)
    private long expireTime;

    public byte[] getSecretKeyBytes() {
        if (secretKeyBytes == null) {
            secretKeyBytes = Decoders.BASE64.decode(secretKey);
        }
        return secretKeyBytes;
    }
}
